/**
 * Created by Administrator on 2016/12/17.
 */
// 仅选择日期
$(".form-date").datetimepicker(
    {
        language:  "zh-CN",
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0,
        format: "yyyy-mm-dd"
    });
/*解析href*/
var str = location.search;
str = str.slice(1).split('&');
var json = {};
for (var i = 0; i < str.length; i++) {
    var a = str[i].split('=');
    json[a[0]] = a[1];
}
//console.log(json);

$(function () {
    /*初始化*/
    init();

    $('#addClick').click(function(){
        layer.open({
            type: 2,
            maxmin: false,
            shadeClose: false,
            closeBtn: 1,
            area : ['30%' , '80%'],
            content:`platform-ein-inn2.html?projectCode=${json.projectCode}&teamId=${json.teamId}&userCode=${json.userCode}&categoryId=${1}&shopId=${json.shopId}&shopName=${json.shopName}&mpId=${json.mpId}&id=${json.id}&merchandiseType=${3}&buyType=${2}`,
            title :　false,
            end:function(){
                //console.log("结束刷新");
                $("#workTable").bootstrapTable('refresh',oUrl);
            }
        });
    });
    $('#checkClick').click(function(){
        var oStartTime = $('#startTime').val();
        var oEndTime = $('#endTime').val();

        if(oStartTime!==''&& oEndTime!==''){
            $.get(`http://192.168.59.3:8082/console/shopping/leaseMatssubSingle?shopId=${json.shopId}&categoryId=${json.categoryId}&projectCode=${json.projectCode}&startTime=${oStartTime}&endTime=${oEndTime}&pageNum=1&pageSize=10`);
        }

    });
});
var oUrl =`http://192.168.59.3:8082/console/shopping/leaseMatssub?categoryId=${json.categoryId}&projectCode=${json.projectCode}&pageNum=1&pageSize=10`;

function init(){
    $('#workTable').bootstrapTable({
        method : 'get',  //发送方式
        url : oUrl,
    })
}

function handlerFmt(value,row){
    //console.log(row);
    return `<span onclick="oEditFun('${row.receptionAt}','${row.categoryName}','${row.attribute}','${row.merchandiseUnit}','${row.actualPrice}','${row.quantity}','${row.adjustQuantity}','${row.adjustReason}','${row.totalPrice}','${row.id}','${row.adjustReceptionAt}','${row.adjustReturnAt}')" class='edit'>编辑</span><span onclick="oDelFun('${row.id}')" class='del'>删除</span>`
}
function oEditFun(code1,code2,code3,code4,code5,code6,code7,code8,code9,code10,code11,code12){
    layer.open({
        type: 2,
        maxmin: false,
        shadeClose: false,
        closeBtn: 1,
        area : ['30%' , '80%'],
        content:`platform-ein-inn2.html?edit=1&projectCode=${json.projectCode}&shopId=${json.shopId}&teamId=${json.teamId}&userCode=${json.userCode}&receptionAt=${code1}&categoryName=${code2}&attribute=${code3}&merchandiseUnit=${code4}&actualPrice=${code5}&quantity=${code6}&adjustQuantity=${code7}&adjustReason=${code8}&totalPrice=${code9}&merchandiseType=${2}&buyType=${1}&id=${code10}&adjustReceptionAt${code11}&adjustReturnAt=${code12}`,
        title :　false,
        end:function(){
            //console.log("结束刷新");
            $("#workTable").bootstrapTable('refresh',oUrl);
        }
    });
}
/*回调函数*/
function responseHandler(res) {
    var oLists = res.data.list;
    var newDate = new Date();
    for (var i=0; i<oLists.length; i++){
        res.data.list[i].receptionAt = newDate.toLocaleDateString(oLists[i].receptionAt);
    }
    var needData = {
        rows: res.data.list,
        total: res.data.total
    };

    return needData;
}
/*每页序号*/
function indexFmt(val,row,index){
    return index+1;
}
/*分页器*/
function workTableQuery(params){
    params["pageNum"] = (params.offset / params.limit) + 1;
    params.pageSize = params.limit;

    return params;
}